package oa.hleast.xswl.service.oms.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.xswl.mapper.OmsOrderRefundLogMapper;
import oa.hleast.xswl.pojo.domain.oms.OmsOrderRefundLog;
import oa.hleast.xswl.pojo.vo.oms.ShowOrderRefundLogVo;
import oa.hleast.xswl.service.oms.OmsOrderRefundLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: 302
 * @date: 2021-11-05 11:49:01
 * @description: 订单退款操作记录表(OmsOrderRefundLog)接口实现
 */
@Transactional
@Slf4j
@AllArgsConstructor
@Service("omsOrderRefundLogService")
public class OmsOrderRefundLogServiceImpl extends ServiceImpl<OmsOrderRefundLogMapper, OmsOrderRefundLog> implements OmsOrderRefundLogService {

    @Override
    public Boolean saveRefundLog(OmsOrderRefundLog log) {
        return this.save(log);
    }

    @Override
    public List<ShowOrderRefundLogVo> findRefundLog(Long refundId) {
        List<OmsOrderRefundLog> list = this.list(new LambdaQueryWrapper<OmsOrderRefundLog>()
                .eq(OmsOrderRefundLog::getRefundId, refundId)
                .orderByDesc(OmsOrderRefundLog::getId)
                .orderByDesc(OmsOrderRefundLog::getGmtCreate)

        );

        List<ShowOrderRefundLogVo> msgList = list.stream().map(pojo -> {
            ShowOrderRefundLogVo vo = new ShowOrderRefundLogVo();
            BeanUtil.copyProperties(pojo, vo);
            return vo;
        }).collect(Collectors.toList());
        log.info("msgList = {}", msgList);
        return msgList;
    }
}
